#include <stdlib.h>
#include <stdio.h>

#include "../../libs/Utils/BasicTypes.h"
#include "../../libs/Utils/Utils.h"
#include "../../libs/LocalStack/LocalStack.h"

#include "../../libs/SparceMatrix/sparse_matrix.h"
#include "../../libs/SparceMatrix/LinearIO.h"
#include "../../libs/Containers/NumList.h"
#include "../../libs/Containers/NumListIO.h"
#include "../../libs/LinearComputation/Matrix.h"
#include "../../libs/LinearComputation/ModularityMatrix.h"

#include "Main.h"

int main(int argv, char* argc[])
{	
	InitGlobalStack();
	START();
	
	if (argv > 3)
	{
		Assert(printf("Not enough arguments.") > 0);
		RETURN(1);
	}	
		
	if (Run(argc[1], argc[2]))
		RETURN(0)
	
	RETURN(1);
}

bool Run(const char* matrixFileName, const char* groupFileName)
{	
	sparse_matrix_lst* matrix;
	NumList* group;
	elem* modulMatrix;
	
	START();
	
	if (NULL == (matrix = ReadInMatrix(matrixFileName)))
	{
		printf("Faild to read in the matrix.");
		RETURN(FALSE);
	}
	
	SAFED(matrix, free_sparse_matrix_lst);
	
	if (NULL == (group = ReadNumList(groupFileName)))
	{
		printf("Failed to read in the group.");
		Delete(matrix);
		RETURN(FALSE);
	}
	
	SAFED(group, DeleteNumList);
	
	SAFE(modulMatrix = CreateModularityMatrix(matrix, group));
	PrintMatrix(modulMatrix, group->size);
	
	DeleteLocalStack();
	RETURN(TRUE);
}
